//
//  NSString+YSExtension.h
//  YSKitDemo
//
//  Created by Kyson on 2018/9/25.
//  Copyright © 2018年 YangShen. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

typedef NS_ENUM(NSInteger, YSFileNameType) {
    YSFileNameTypeDocuments = 0,
    YSFileNameTypeLibrary,
    YSFileNameTypeTmp,
};

@interface NSString (YSExtension)

#pragma mark - Add
- (BOOL)haveImageSuffix;

/// 文字变灰
- (NSAttributedString *)getAttributeStringFrom:(NSUInteger)fromNum length:(NSUInteger)length;

/// 关键字变色
- (NSAttributedString *)getAttributeStringWithKeyword:(NSString *)keyword color:(UIColor *)color;

#pragma mark - 分割字符串
/**
 将字符串按千分位 逗号，分割方法
 */
- (NSString *)ys_changeNumberFormat;

#pragma mark - Size
/**
 *  字符串的Size
 *
 *  @param font 字符串的字体
 *  @param size 最大的尺寸
 *
 *  @return 按照给定的尺寸得到的Size
 */
- (CGSize)ys_sizeForFont:(UIFont *)font size:(CGSize)size mode:(NSLineBreakMode)lineBreakMode;

/**
 * 字符串宽度
 */
- (CGFloat)ys_widthForFont:(UIFont *)font;

/**
 * 字符串高度
 */
- (CGFloat)ys_heightForFont:(UIFont *)font width:(CGFloat)width;

#pragma mark - 正则
/**
 * 是否匹配到该正则
 */
- (BOOL)ys_matchesRegex:(NSString *)regex options:(NSRegularExpressionOptions)options;

/**
 * 对匹配到的字符串进行操作
 */
- (void)ys_enumerateRegexMatches:(NSString *)regex options:(NSRegularExpressionOptions)options usingBlock:(void (^)(NSString *match, NSRange matchRange, BOOL *stop))block;

/**
 * 将匹配到的字符串替换掉
 */
- (NSString *)ys_stringByReplacingRegex:(NSString *)regex options:(NSRegularExpressionOptions)options withString:(NSString *)replacement;

/**
 * 验证邮箱格式是否正确
 */
- (BOOL)ys_validateEmail;

/**
 * 验证手机号码格式是否正确
 */
- (BOOL)ys_validateMobile;

/**
 *  验证固话号码格式是否正确
 */
- (BOOL)ys_validateLandlinePhone;

- (BOOL)ys_validateWebUrl;

/**
 * 验证密码格式是否正确
 */
- (BOOL)ys_validatePassword;
- (BOOL)ys_validateComplexPassword;

// 测试真实姓名的合法性(只有中英文)
- (BOOL)checkRealname;

/**
 *  是否包含中文字符
 */
- (BOOL)ys_containChinese;

#pragma mark - Help
/**
 返回UUID
 e.g. "D1178E50-2A4D-4F1F-9BD3-F6AAB00E06B1"
 */
+ (NSString *)ys_stringWithUUID;

/**
 * 清空所有空字符
 */
- (NSString *)ys_clearSpace;

/**
 *  清空字符串中两端的空白字符
 */
- (NSString *)ys_trimString;

/**
 *  是否空字符串
 */
- (BOOL)ys_isEmptyString;

/**
 *  返回沙盒中的文件路径
 */
+ (NSString *)ys_documentsPath;
+ (NSString *)ys_documentsPath:(YSFileNameType)type;

/**
 *  转码，去掉Url中文字符
 */
- (NSString *)ys_urlEncoding;

/**
 *  解码
 */
- (NSString *)ys_urlDecoding;

@end

NS_ASSUME_NONNULL_END
